package com.personalsystem.role.bean;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.personalsystem.function.bean.Functions;


@Entity
@Table(name="ROLE")
public class Role implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Long id;
	
	private String name;
	
	private String remark;
	
	private String remarkUbb;
	
	private Set<Functions> funSet=new HashSet<Functions>();
	
	private Integer status;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	
	@Column(name="NAME")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Column(name="REMARK")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	@Column(name="REMARK_UBB")
	public String getRemarkUbb() {
		return remarkUbb;
	}

	public void setRemarkUbb(String remarkUbb) {
		this.remarkUbb = remarkUbb;
	}


	@Column(name="STATUS")
	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}
	

    @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)  
    @JoinTable(name = "Role_Functions",   
            joinColumns ={@JoinColumn(name = "role_functions_rid", referencedColumnName = "id") },   
            inverseJoinColumns = { @JoinColumn(name = "role_functions_fid", referencedColumnName = "id")   
    })  
	public Set<Functions> getFunSet() {
		return funSet;
	}

	public void setFunSet(Set<Functions> funSet) {
		this.funSet = funSet;
	}
	
	public void addFunction(Functions functions) {  
        if (!this.funSet.contains(functions)) {//检测在该散列表中某些键是否映射到指定值,value 查找的值。如果某些键映射到该散列表中的值为true，否则false  
            this.funSet.add(functions);  
        }  
    }  
  
    public void removeFunction(Functions functions) {  
        this.funSet.remove(functions);  
    }  

	
}
